<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'controllers/admin.php';

/**
 * Контроллер просмотра и редактирования стилей
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class Admin_Manage_Styles extends Admin {
   
   /**
    * Конструктор класса
    *
    * @access public
    * @return Admin_Manage_Styles
    */
   function Admin_Manage_Styles() {
      parent::Admin();
      $this->set_menu(4, 4);
      $this->load->language('button');
   } // end Admin_Manage_Styles
   
   /**
    * Метод по умолчанию
    *
    * @access public
    */
   function index() {
      $data = array();
      $this->load->helper('link');
      $this->load->model('m_select_styles');
      $this->load->library('table_builder');
      $this->table_builder->set_model($this->m_select_styles);
      $this->table_builder->add_button(create_link($this->get_controller(), 'add'), $this->lang->line('add_button'));
      $this->table_builder->add_button(create_link($this->get_controller(), 'edit'), $this->lang->line('edit_button'));
      $this->table_builder->add_button(create_link($this->get_controller(), 'delete'), $this->lang->line('delete_button'), $this->lang->line('styles_delete_confirmation'));
      $data['table'] = $this->table_builder->generate();
      $this->set_content($this->parser->parse('admin/manage_styles.html', $data, true));
      $this->display();
   } // end index
   
   /**
    * Метод удаления записи
    *
    * @access public
    */
   function delete() {
      $ids = $this->input->post('ids');
      if (is_array($ids) && 0 < count($ids)) {
         $this->load->model('m_style');
         foreach ($ids as $id) {
            $this->m_style->set_id($id);
            $this->m_style->delete();
         }
         $this->set_message($this->lang->line('delete_styles_succ'), 'info', true);
      }
      $this->redirect($this->get_controller());
   } // end pause
   
   /**
    * Метод добавления записи
    * Редирект на нужный контроллер
    *
    * @access public
    */
   function add() {
      $this->redirect('admin_update_style');
   } // end add
   
   /**
    * Метод изменения записи
    * Редирект на нужный контроллер
    *
    * @access public
    */
   function edit() {
      $ids = $this->input->post('ids');
      if (is_array($ids) && 0 < count($ids)) {
         $id = array_shift($ids);
         $this->redirect('admin_update_style', '', array('id' => $id));
      }
      $this->redirect($this->get_controller());
   } // end edit
   
}
